package spe.model.spem;

import java.beans.PropertyChangeEvent;
import java.util.ArrayList;
import java.util.List;


public class TaskDefinitionImpl extends AbstractMethodContentElement implements TaskDefinition
{
	protected List<Step> steps = null;
	protected ToolDefinition toolUse;
	protected Qualification requiredQualification;
	
	protected RoleDefinition primaryPerformer;
	protected List<RoleDefinition> additionalPerformers = new ArrayList<RoleDefinition>();
	
	protected List<WorkDefinitionParameter> parameters = new ArrayList<WorkDefinitionParameter>();
	protected List<Constraint> preConditions = new ArrayList<Constraint>();
	protected List<Constraint> postConditions = new ArrayList<Constraint>();
	
	public List<Step> getSteps()
	{
		return steps;
	}
	
	public void setSteps(List<Step> st)
	{
		steps = st;
	}
	
	public void addStep(Step step)
	{
		if(steps == null)
			steps = new ArrayList<Step>();
		steps.add(step);
		
		firePropertyChange("STEP", null, step);
	}

	@Override
	public void setParameters(List<WorkDefinitionParameter> params)
	{
		List<WorkDefinitionParameter> old = this.parameters; 
		parameters = params;
		firePropertyChange("Parameter", null, params);
	}

	@Override
	public List<Constraint> getPreConditions() {
		// TODO Auto-generated method stub
		return preConditions;
	}

	@Override
	public void setPreConditions(List<Constraint> preCons) 
	{
		preConditions = preCons;
	}

	@Override
	public List<Constraint> getPostConditions() 
	{
		return postConditions;
	}

	@Override
	public void setPostConditions(List<Constraint> postCons) 
	{
		postConditions = postCons;
	}

	@Override
	public List<WorkDefinitionParameter> getParameters() 
	{
		return parameters;
	}

	@Override
	public void setDescription(String des) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public String getDescription() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public RoleDefinition getPrimaryPerformer()
	{
		return primaryPerformer;
	}

	@Override
	public void setPrimaryPerformer(RoleDefinition performer)
	{
		Object oldValue = this.primaryPerformer; 
		this.primaryPerformer = performer;
		firePropertyChange("Performer", oldValue, performer);
	}

	@Override
	public List<RoleDefinition> getAdditionalPerformers()
	{
		return additionalPerformers;
	}

	@Override
	public void setAdditionalPerformers(List<RoleDefinition> lst)
	{
		this.additionalPerformers = lst;
	}

	@Override
	public void addAdditionalPerformer(RoleDefinition performer)
	{
		this.additionalPerformers.add(performer);
		firePropertyChange("AdditionalPerformer", null, performer);
	}

	@Override
	public void removeAdditionalPerformer(RoleDefinition performer)
	{
		this.additionalPerformers.remove(performer);
		firePropertyChange("Performer", performer, null);
	}
	
	@Override
	public List<SPEMElement> getAllNestedElements()
	{
		List<SPEMElement> lst = new ArrayList<SPEMElement>();
		
		lst.addAll(steps);
		lst.add(toolUse);
		lst.add(requiredQualification);
		lst.add(primaryPerformer);
		lst.addAll(additionalPerformers);
		lst.addAll(preConditions);
		lst.addAll(postConditions);
		
		return lst;
	}

	@Override
	public void propertyChange(PropertyChangeEvent evt) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public String getElementId() {
		// TODO Auto-generated method stub
		return null;
	}

}
